package com.itheima.Service.impl;

import com.itheima.Service.DeptService;
import com.itheima.entity.Dept;
import com.itheima.mapper.DeptMapper;
import com.itheima.mapper.EmpExprMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

// 业务逻辑处理层
@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    /**
     * 查询所有部门
     * @return
     */
    public List<Dept> list() {
        // 1.调用mapper层的list()方法，并返回数据
        return deptMapper.list();
    }

    /**
     * 根据ID删除部门
     * @param id
     */
    @Override
    public void delete(Integer id) {
        deptMapper.delete(id);
    }

    @Override
    public void add(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.add(dept);
    }

    @Override
    public Dept getById(Integer id) {
        return deptMapper.getById(id);
    }

    // 修改部门
    @Override
    public void update(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.update(dept);
    }
}
